package com.qf.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AspectTest {

    @Pointcut("execution(* com.qf.service..*.*(..))")
    public void pc(){}

    @Around("pc()")
    public Object around(ProceedingJoinPoint joinPoint) {
        try {
            System.out.println("前置增强");
            //执行原始方法，返回值是原始方法返回值
            Object result = joinPoint.proceed();
            System.out.println("后置增强");
            return result;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("异常增强");
        } finally {
            System.out.println("最终增强");
        }
        return null;
    }
    /* @Before("pc()")
    public void before(JoinPoint joinPoint) {
        //获取执行的类
        Class<?> clazz = joinPoint.getTarget().getClass();
        System.out.println("类名:"+clazz);
        //过去执行方法名
        String name = joinPoint.getSignature().getName();
        System.out.println("方法名:"+name);
        Object[] args = joinPoint.getArgs();
        System.out.println("参数列表:" + Arrays.toString(args));
        System.out.println("前置增强");
    }
    @After("pc()")
    public void after() {
        System.out.println("最终增强");
    }
    @AfterThrowing("pc()")
    public void afterThrowing() {
        System.out.println("前置增强");
    }
    @AfterReturning("pc()")
    public void afterReturning() {
        System.out.println("后置增强（有异常则不执行）");
    }*/
}